package com.liu.efk.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

/**
 * Created by shi860715@126.com
 * Date 2021/8/19 10:16
 * Description
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket docket(Environment environment) {

//        在开发环境中，或者测试环境中开启swagger
        Profiles profiles =Profiles.of("dev","test");
//        通过预定义的 条件返回项目在运行的环境结果
        final boolean flag = environment.acceptsProfiles(profiles);

        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .enable(true)
                .select()
//                  RequestHandlerSelectors  配置扫描接口的方式
//                basePackage  指定扫描的包
//                any 全部扫描
//                none 不扫描
//                withClassAnnotation 扫描类上的注解
//                withMethodAnnotation 扫描方法上的注解
//
                .apis(RequestHandlerSelectors.basePackage("com.liu"))
//                 过滤路径  扫描包，且访问路径在/admin下的所有接口
//                .paths(PathSelectors.ant("/admin/**"))
                .build();
    }


    @Bean
    ApiInfo apiInfo() {
        final Contact contact = new Contact("刘必君", "https://blog.csdn.net/shi860715", "shi860715@126.com");
        return new ApiInfo("生兴基本机构封装",
                "Api 文档",
                "1.0",
                "https://blog.csdn.net/shi860715",
                contact,
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList());
    }

}
